<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_gdqh_t {
        background-color: #254060;
        height: 377px;
        color: white;
        overflow: auto;
    }

    .pa_gdqhHis_but {
        height: 58px;
        line-height: 58px;
        margin-left: 40px;
        font-size: 30px;
        width: 120px;
        color: white;
        text-align: center;
        float: right;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>工单历史数据</p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center" style="margin-left: 2%;margin-right: 4%;">
            <div class="aui-flex-item-12">
                <div class="aui-flex-item-6">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <ul class="aui-list aui-form-list">
                                <li class="aui-list-item" style="background-color: #D9D8DB; border: 0;">
                                    <div class="aui-list-item-inner" style="background-color: #D9D8DB; border: 0;">
                                        <div class="aui-list-item-label">计划日期：</div>
                                        <div class="aui-list-item-input" style="background-color: white;"
                                            onclick="timePicker('planDate');">
                                            <input type="text" placeholder="选择日期" class="aui-input" id="planDate">
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="aui-flex-item-6">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <div class="pa_gdqhHis_but" style="background-color: #D9001B;" onclick="cancle()">关闭</div>
                            <div class="pa_gdqhHis_but" style="background-color: #00BFBF;" onclick="doSearch()">查询</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="aui-flex-col aui-flex-center" style="margin-top: 1%;">
            <div class="aui-flex-item-12">
                <div class="aui-flex-col pa_gdqh_t">
                    <div class="aui-flex-item-12">
                        <div style="height: 100%;width: 100%;">
                            <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr style="text-align: center;color: white;font-size: 15px;height: 35px;">
                                        <td algin='center' style="width:5%">序号</td>
                                        <td algin='center' style="width:18%">工单号</td>
                                        <td algin='center' style="width:15%">物料编码</td>
                                        <td algin='center' style="width:15%">物料名称</td>
                                        <td algin='center' style="width:7%">计划数</td>
                                        <td algin='center' style="width:7%">完工数</td>
                                        <td algin='center' style="width:7%">合格数</td>
                                        <td algin='center' style="width:8%">不合格数</td>
                                        <td algin='center' style="width:12%">计划日期</td>
                                        <td algin='center' style="width:6%">状态</td>
                                    </tr>
                                </thead>
                                <tbody id="workOrderHtml">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = ""
    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();

        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //初始化当前日期
        crateDate();

        //3:工单信息
        doSearch();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //获取当前日期
    function crateDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        $("#planDate").val(year + "-" + month + "-" + day);
        doSearch();
    }

    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#" + id).val(date);
            }
        });
    }

    //查询工单信息
    function doSearch() {
        var proddate = $("#planDate").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyWorkOrder";
        var data = {
            values: {
                proddate: proddate,
                workCenterCode: api.pageParam.workCenterCode,
                workCenterName: api.pageParam.workCenterName,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 15px;height:35px;'>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='workOrderCode'>" + list[i].workOrderCode + "</td>";
                        html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                        html += "<td name='mrlName'>" + list[i].mrlName + "</td>";
                        html += "<td name='planQty'>" + list[i].planQty + "</td>";
                        html += "<td name='completeQty'>" + list[i].completeQty + "</td>";
                        html += "<td name='qualityQty'>" + list[i].qualifyQty + "</td>";
                        html += "<td name='unQualityQty'>" + list[i].unQualifyQty + "</td>";
                        html += "<td name='planDate'>" + list[i].proddate + "</td>";
                        html += "<td name='status'>" + list[i].state + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("workOrderHtml"), html);

                } else {
                    $api.html($api.byId("workOrderHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //刷新按钮
    function refresh() {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        //工单信息
        doSearch();
    }

    //关闭，返回上级
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: api.pageParam.name,
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>